import {FontSize, FontStyle, FontWeight} from './FontExtraState';

interface IFont{
  code:number;
  render(size?:FontSize, style?:FontStyle, weight?:FontWeight):void;
}

// 共享的
class Font implements IFont{
  code:number;
  lowerCase:number;
  upperCase:number;
  constructor(code:number){
    this.code = code;
    this.lowerCase = code;
    this.upperCase = code + 24;
  }
  render(size:FontSize, style:FontStyle, weight:FontWeight):void{
    console.log(`渲染文字：小写码[${this.lowerCase}] / 大写码[${this.upperCase}] / 字号[${size.value}] / 样式[${style.value}] / 字粗[${weight.value}]`);
  }
}

class IconFont implements IFont{
  code:number;
  path:string;
  size:FontSize;
  style:FontStyle;
  weight:FontWeight;
  constructor(code:number,path:string,size:FontSize, style:FontStyle, weight:FontWeight){
    this.code = code;
    this.path = path;
    this.size = size;
    this.style = style;
    this.weight = weight;
  }
  render():void{
    console.log(`渲染图标：码点[${this.code}] / 路径[${this.path}] / 大小[${this.size.value}] / 风格[${this.style.value}] / 粗细[${this.weight.value}]`);
  }
  setState(size:FontSize, style:FontStyle, weight:FontWeight):void{
    this.size = size;
    this.style = style;
    this.weight = weight;
  }
}

class FontFactory{
  static fontPool:Map<string, Font> = new Map();
  static getFont(key:string):Font{
    if(FontFactory.fontPool.has(key)){
      console.log(`找到${key}，返回已有对象`);
      return FontFactory.fontPool.get(key);
    }else{
      console.log(`未找到${key}，创建新对象`);
      let font = new Font(key.codePointAt(0));
      FontFactory.fontPool.set(key, font);
      return font;
    }
  }
}

export {IconFont, FontFactory};